//
//  ArrowView.m
//  BeeWeb
//
//  Created by Jimmy on 28/10/2010.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ArrowView.h"


@implementation ArrowView


- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // Initialization code
		self.userInteractionEnabled = YES;
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
/*
- (void)dealloc {
    [super dealloc];
}*/
/*
- (void) setDirection:(NSInteger)dir {
	if (dir == kLeft) {
		self.image = [UIImage imageNamed:@"left.png"];
	}
	else {
		self.image = [UIImage imageNamed:@"right.png"];
	}
	direction = dir;
}
*/
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	scrollTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(scrollBar) userInfo:nil repeats:YES];
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	if ([scrollTimer isValid]) {
		[scrollTimer invalidate];
		scrollTimer = nil;
	}
}

- (void) scrollBar {
	if (self.delegate != nil) {
		if ([_delegate conformsToProtocol:@protocol(ArrowViewDelegate)]) {
			if ([_delegate respondsToSelector:@selector(scroll:withDirection:)]) {
				self.hidden = [self.delegate scroll:self withDirection:_direction];
				if (self.hidden) {
					if ([scrollTimer isValid]) {
						[scrollTimer invalidate];
						scrollTimer = nil;
					}
				}
			}
		}
	}
}

-(void) dealloc{

}

@end
